import { SelectComponent } from './../shared/select/select.component';
import { NzModalService } from 'ng-zorro-antd';
import { Component, OnInit } from '@angular/core';
import { Globals } from './../../../shared/global';
import { CustomerService } from '../services/customer';
import { Customer } from '../domain/customer'
import { Router } from '@angular/router';
import { RouterState } from '@angular/router';

@Component({
  selector: 'ree-customer-list',
  templateUrl: './customer-list.component.html',
  styleUrls: ['./customer-list.component.scss']
})
export class CustomerListComponent implements OnInit {
  filter={
    dealerAccounts:'',
    companyName:''
  }
  customersList = [];
  constructor(
    private CustomerService: CustomerService,
    public router: Router,
    private globals: Globals,
    private modalService: NzModalService
  ) {}

  ngOnInit() {
    this.getCustomersList()
  }

  //获取直销客户列表
  getCustomersList() {
    this.CustomerService.getCustomersList().then(data => this.customersList = data)
  }

  //打开验证公司对话框 加载modal
  createCustomer() {
    const subscription = this.modalService.open({
      title: '关联客户',
      content: SelectComponent,
      wrapClassName:'vertical-center-modal',
      footer: false,
      componentParams: {
        name: 'customer'
      }
    });
    subscription.subscribe(result => {   
      if (result === "skip") { this.skipToCreate() }
    })
  }

  //跳转到创建客户页
  skipToCreate() {
    this.router.navigate(["work/sell/create", "customer"]);
    this.globals.paths.path.push({ name: "新增客户", route: 'sell/create' })
  }

  //跳转到设备列表页，携带客户账户数据
  skipToDevices(data) {
    this.router.navigate(["work/equipment/list", data.customerAccounts]);
    this.globals.paths.path.push({ name: data.customerAccounts + "的设备列表", route: null })
  }

  //跳转到绑定设备页，携带客户账户数据
  skipToBind(data) {
    this.router.navigate(["work/equipment/bind", data.customerAccounts]);
    this.globals.paths.path.push({ name: "绑定设备", route: null }, { name: data.customerAccounts, route: null })
  }
}
